<?php
include('top.php');
require_once('pasmy/dbwaarden.php');
/*echo "dbhost = $dbhost<br>";*/
echo "<br><br>";
$mysql_id = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($db, $mysql_id);
if(isset($_POST["jaar"])) {
$waardb = "vnzvrn" . $_POST["jaartal"];
$jaaar = $_POST["jaartal"];
$tel=0;
$sql = "select driver from $waardb";
$res = mysql_query($sql, $mysql_id);
while ($row = mysql_fetch_row($res)) {
	$chauffeurs[] = $row[0];
}
mysql_free_result($res);
$chauffeurs = array_unique($chauffeurs);

$aantaldrivers = count($chauffeurs);
$aantaldrivers++;
//echo "aantaldrivers = $aantaldrivers<br>";

?>
<table border="1" align="center" cellpadding="8">
<tr>
<td class = "delsaux2"><?php echo $_POST["jaartal"];?></td>
<?php
foreach($chauffeurs as $value) {
	echo "<td class='delsaux2'> $value </td>";
}
?>
<td class="delsaux2">Total</td></tr>
<tr>
<td class="zones"><?php echo $januari[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs,gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-01-01' AND `datum` <= '$jaaar-01-31' AND `driver` LIKE '%$value%'";
   //echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		//echo "row0 = $row[0] en row1 = $row[1]<br>";
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
?>

</tr>
</tr>
<tr>
<td class="zones"><?php echo $februari[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs,gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-02-01' AND `datum` <= '$jaaar-02-29' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;

?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $maart[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-03-01' AND `datum` <= '$jaaar-03-31' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;

?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $april[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-04-01' AND `datum` <= '$jaaar-04-30' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
 
?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $mei[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-05-01' AND `datum` <= '$jaaar-05-31' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
 
?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $juni[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-06-01' AND `datum` <= '$jaaar-06-30' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
 
?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $juli[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-07-01' AND `datum` <= '$jaaar-07-31' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
		//echo "tprijs = $tprijs<br>";
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
 
?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $augustus[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-08-01' AND `datum` <= '$jaaar-08-31' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
 
?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $september[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-09-01' AND `datum` <= '$jaaar-09-30' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
 
?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $oktober[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-10-01' AND `datum` <= '$jaaar-10-31' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
 
?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $november[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-11-01' AND `datum` <= '$jaaar-11-30' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
 
?>
</tr>
</tr>
<tr>
<td class="zones"><?php echo $december[$taal];?></td>
<?php
$tprijs = 0;
foreach($chauffeurs as $value) {
	//echo "chauffeur = $value <br>";
$sql = "SELECT prijs, gasoil  FROM `$waardb` WHERE `datum` >= '$jaaar-12-01' AND `datum` <= '$jaaar-12-31' AND `driver` LIKE '%$value%'";
//echo "sql = $sql <br>";
$res = mysql_query($sql, $mysql_id);
	while ($row = mysql_fetch_row($res)) {
		$tprijs = $tprijs + $row[0] + $row[1];
	}
echo "<td class='center'>" . number_format($tprijs,2,',', '.') ."</td>";
$driver[$value] = $driver[$value] + $tprijs;
$maandprijs = $maandprijs + $tprijs;
$tprijs = 0;
}
echo "<td class='totaalzones'>" . number_format($maandprijs,2,',', '.') . "</td>";
$maandprijs = 0;
 
?>
</tr>
<tr>
<td>&nbsp;</td>
<?php
foreach($driver as $key => $value) {
	
	echo "<td class = 'delsaux'>" . number_format($value,2,',', '.') . "</td>";
	$totverdiend = $totverdiend + $value;
	
}
$spanning = $aantaldrivers +1;
echo "aantaldrivers = $spanning<br>";
?>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="<?php echo $spanning;?>" class="delsaux2">
<?php
echo '<div style="text-align: center">' . number_format($totverdiend,2,',', '.') . '</div>';
?>
</td>
</tr>
</table>
<br /><br />

<?php
 /*foreach($driver as $key => $value) {
	
	echo "sleutel = $key en waarde  = $value<br>";
	
}*/
}
else {
	$jaartal = date("Y");
?>	
<form action="totalen.php" method="post">
<table align="center" width="40%" border="1">
<tr><td colspan="2" class="delsaux2"><?php echo $totc[$taal];?></td></tr>
<tr><td width="30%"><strong><?php echo $totjaar[$taal];?></strong></td><td width="10%"><input type="text" name="jaartal"  value="<?php echo $jaartal;?>" /></td></tr>
<tr><td colspan="2"><div style="text-align: center"><br /><input type="submit" name="jaar" value="<?php echo $tonen[$taal];?>"/></div></td></tr>
</table>

</form>
<?php		
}
include('footer.php');
?>